<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  Function.prototype.myCall = function (context, ...args) {
    const ctx = context || window;
    ctx.fn = this;
    // 谁调用，this就指向谁
    const result = ctx.fn(...args);
    delete ctx.fn;
    return result;
  };
  Function.prototype.myApply = function (context, args = []) {
    const ctx = context || window;
    // 临时复制
    ctx.fn = this;
    // 谁调用，this就指向谁
    const result = ctx.fn(...args);

    delete ctx.fn;
    return result;
  };

  const obj = { name: 'allen' };

  function say(param1, param2) {
    console.log(param1, param2, this.name);
  }

  say.myCall(obj, 'man', 27);
  say.myApply(obj, ['man', 27]);
</script>
</body>
</html>
